home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / gems / g_gemsi.lha / GraphicsGems / PolyScan / poly.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-10  |  1.9 KB  |  63 lines

  1.  
  2. /* poly.h: definitions for polygon package */
  3.  
  4. #ifndef POLY_HDR
  5. #define POLY_HDR
  6.  
  7. #define POLY_NMAX 8    /* max #sides to a polygon; change if needed */
  8.  
  9. typedef struct {        /* A POLYGON VERTEX */
  10.     double sx, sy, sz, sw;     /* screen space position  */
  11.                             /* (sometimes homo.) */
  12.     double x, y, z;        /* world space position */
  13.     double u, v, q;        /* texture position */
  14.                         /* (sometimes homogeneous) */
  15.     double r, g, b;        /* (red,green,blue) color */
  16.     double nx, ny, nz;        /* world space normal vector */
  17. } Poly_vert;
  18. /* update poly.c if you change this structure */
  19.  
  20. typedef struct {        /* A POLYGON */
  21.     int n;            /* number of sides */
  22.     int mask;            /* interpolation mask for vertex elems */
  23.     Poly_vert vert[POLY_NMAX];    /* vertices */
  24. } Poly;
  25. /*
  26.  * mask is an interpolation mask whose kth bit indicates whether the kth
  27.  * double in a Poly_vert is relevant.
  28.  * For example, if the valid attributes are sx, sy, and sz, then set
  29.  *    mask = POLY_MASK(sx) | POLY_MASK(sy) | POLY_MASK(sz);
  30.  */
  31.  
  32. typedef struct {        /* A BOX (TYPICALLY IN SCREEN SPACE) */
  33.     double x0, x1;        /* left and right */
  34.     double y0, y1;        /* top and bottom */
  35.     double z0, z1;        /* near and far */
  36. } Poly_box;
  37.  
  38.  
  39. typedef struct {        /* WINDOW: A DISCRETE 2-D RECTANGLE */
  40.     int x0, y0;            /* xmin and ymin */
  41.     int x1, y1;            /* xmax and ymax (inclusive) */
  42. } Window;
  43.  
  44. #define POLY_MASK(elem) (1 << (&poly_dummy->elem - \
  45.                              (double *)poly_dummy))
  46.  
  47. #define POLY_CLIP_OUT 0        /* polygon entirely outside box */
  48. #define POLY_CLIP_PARTIAL 1    /* polygon partially inside */
  49. #define POLY_CLIP_IN 2        /* polygon entirely inside box */
  50.  
  51. extern Poly_vert *poly_dummy;    /* used superficially by */
  52.                             /* POLY_MASK macro */
  53.  
  54. void    poly_print(/* str, p */);
  55. void    poly_vert_label(/* str, mask */);
  56. void    poly_vert_print(/* str, v, mask */);
  57. int        poly_clip_to_box(/* p1, box */);
  58. void    poly_clip_to_halfspace(/* p, q, index, sign, k, name */);
  59. void    poly_scan(/* p, win, pixelproc */);
  60.  
  61. #endif
  62.  
  63.